package com.ruoyi.newSystem.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.BaseMapperX;
import com.ruoyi.common.core.domain.entity.RoleDO;
import com.ruoyi.common.core.domain.entity.UserDeptDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;

/**
 * The interface User role mapper.
 */
@Mapper
public interface UserDeptMapper extends BaseMapperX<UserDeptDO> {


    /**
     * Select by user id list.
     *
     * @param userId the user id
     * @return list
     */
    List<RoleDO> selectByUserId(@Param("userId") Long userId);


    /**
     * Select list by user id list.
     *
     * @param userId the user id
     * @return the list
     */
    default List<UserDeptDO> selectListByUserId(Long userId) {
        return selectList(UserDeptDO::getUserId, userId);
    }

    /**
     * Delete list by user id and role id ids.
     *
     * @param userId  the user id
     * @param deptIds the role ids
     */
    default void deleteListByUserIdAndDeptIds(Long userId, Collection<Long> deptIds) {
        delete(new LambdaQueryWrapper<UserDeptDO>()
                .eq(UserDeptDO::getUserId, userId)
                .in(UserDeptDO::getDeptId, deptIds));
    }

    /**
     * Delete list by user id.
     *
     * @param userId the user id
     */
    default void deleteListByUserId(Long userId) {
        delete(new LambdaQueryWrapper<UserDeptDO>().eq(UserDeptDO::getUserId, userId));
    }

    /**
     * Delete list by role id.
     *
     * @param deptId the role id
     */
    default void deleteListByRoleId(Long deptId) {
        delete(new LambdaQueryWrapper<UserDeptDO>().eq(UserDeptDO::getDeptId, deptId));
    }

    /**
     * Select list by role ids list.
     *
     * @param deptIds the role ids
     * @return the list
     */
    default List<UserDeptDO> selectListByRoleIds(Collection<Long> deptIds) {
        return selectList(UserDeptDO::getDeptId, deptIds);
    }

}
